class Category < ActiveRecord::Base
	has_many :children, :foreign_key => :parent_id, :class_name => "Category"
	belongs_to :parent, :foreign_key => :parent_id, :class_name => "Category"
  has_many :videos

	def breadCrumbLinks( crumbs )
		if self.parent.nil?
			return crumbs.unshift({:id=>self.id, :name=>self.name})
		else		
			return self.parent.breadCrumbLinks ( crumbs ).unshift({:id=> self.id, :name=>self.name})
		end
	end

	def vidCount ( )
		count = 0
		if self.children.empty?
			return self.videos.size
		else
			self.children.each do |child|
				count += child.vidCount				
			end
			return count
		end
	end
end
